package d1231;

import java.util.HashSet;
import java.util.Set;

class Solution {
    public boolean checkPerfectNumber(int num) {
        int sqrt = (int) Math.sqrt(num);
        Set<Integer> set = new HashSet<>();
        if (num == 2 || num == 1) {
            return false;
        }
        for (int i = 2; i <= sqrt; i++) {
            if (num % i == 0) {
                set.add(i);
                set.add(num / i);
            }
        }
        int mul = 1;
        for (Integer s : set) {
            mul += s;
        }

        if (num == mul)
            return true;
        else
            return false;
    }

    public static void main(String[] args) {
        boolean b = new Solution().checkPerfectNumber(7);
        System.out.println(b);
    }
}
